<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="icon" href="<%= BASE_URL %>favicon.ico">
    <title><%= webpackConfig.name %></title>
    <script type="text/javascript" src="http://10.201.37.225:8080/map/arcgis/common/jquery-3.3.1/jquery-3.3.1.min.js">
    </script>
    <script src="http://10.201.37.225:8080/map/arcgis/common/echart/echarts.min.js"></script>
    <script src="http://10.201.37.225:8080/map/arcgis/common/echart/echarts-gl.js"></script>
     <script src="http://10.201.37.225:8080/map/arcgis/VideoFusion/three.js"></script>
    <script src="http://10.201.37.225:8080/map/arcgis/common/AEJson/AEJson-loader.js"></script>
    <script src="http://10.201.37.225:8080/map/arcgis/common/AEJson/AEJson-texture.js"></script>
    <script src="http://10.201.37.225:8080/map/arcgis/common/AEJson/lottie.js"></script>
    <script src="http://10.201.37.225:8080/map/arcgis/common/gl-matrix.js"></script>
    <script src="http://10.201.37.225:8080/map/arcgis/common/hls.min.js"></script>
     <!-- 视频融合 -->
   
    <script src="http://10.201.37.225:8080/map/arcgis/VideoFusion/dat.gui.min.js"></script>
    <script src="http://10.201.37.225:8080/map/arcgis/VideoFusion/OBJLoader.js"></script>
    <script src="http://10.201.37.225:8080/map/arcgis/VideoFusion/FileSaver_js.js"></script>
    <script src="http://10.201.37.225:8080/map/arcgis/VideoFusion/flv.js"></script>
    <script id="vertexShader" type="x-shader/x-vertex">
          precision highp float;
      uniform mat4 modelViewMatrixToFrustum;
      varying highp vec4 vWorldPos;
      varying highp vec4 vCameraPos;
      varying vec3 vColor;
      varying vec2 textureCoord;
      varying vec3 vNormal;
      void main() {

          vColor = color;
          vWorldPos = modelMatrix * vec4(position, 1.0);
          vCameraPos = modelViewMatrixToFrustum * vec4(position, 1.0);
          textureCoord = uv;
          vNormal = normal;
          gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
          gl_Position.z -= 0.20;

      }
    </script>
    <script id="fragmentShader" type="x-shader/x-fragment">
          precision highp sampler2D;
      precision highp float;
      uniform vec3 baseColor;
      uniform vec3 frustum[5];
      uniform sampler2D baseTexture;
      uniform sampler2D cameraTexture;
      uniform int isPreview;
      uniform bool hasBaseTexture;
      uniform bool hasVertexColor;
      uniform vec4 distCoeff;
      uniform bool isFishEyeModel;
      uniform bool useUndistort;
      uniform bool isTransparent;

      varying vec3 vColor;

      varying highp vec4 vWorldPos;
      varying highp vec4 vCameraPos;
      varying vec2 textureCoord;
      varying vec3 vNormal;

      float perspectiveDepthToViewZ( float invClipZ, float near, float far ) {
          return ( near * far ) / ( ( far - near ) * invClipZ - far );
      }

      float viewZToOrthographicDepth( float viewZ, float near, float far ) {
          return ( viewZ + near ) / ( near - far );
      }

      float readDepth( sampler2D depthSampler, vec2 coord ) {
          float fragCoordZ = texture2D( depthSampler, coord ).x;
          float viewZ = perspectiveDepthToViewZ( fragCoordZ, 0.1, 2000000. );
          return viewZ;
      }

      // port from https://github.com/mrdoob/three.js/blob/35ae830a7c4544582ed2759e5b18c5d6ef37c6d9/src/math/Vector3.js#L559
      vec3 projectOnVector(vec3 a, vec3 b){
          float dist = length(b);
          return b * ( dot(a, b) / (dist * dist) );
      }

      float calculateCos(vec3 a, vec3 b){
          float dista = length(a);
          float distb = length(b);
          return (dot(a, b) / (dista * distb));
      }

      void main() {
          // shadowMap = true;
          vec3 baseTextureColor;
          vec3 color;
          baseTextureColor = texture2D(baseTexture, textureCoord).rgb;
          if (hasBaseTexture) {
              gl_FragColor = vec4(baseColor * baseTextureColor, 1.0);
          } else if (hasVertexColor){
              gl_FragColor = vec4(vColor, 1.0);
          }else {
              vec3 view_nv  = normalize(vNormal);
              vec3 nv_color = view_nv * 0.5 + 0.5;
              gl_FragColor  = vec4(isTransparent ? vec3( 0.0, 0.0, 0.0 ) : nv_color, isTransparent ? 0.0 : 1.0);

              // gl_FragColor = vec4(vNormal, 1.0);
          }

          if (isPreview == 1){
              vec3 dir = vCameraPos.xyz - frustum[0];
              vec3 center = (frustum[1] + frustum[2] + frustum[3] + frustum[4]) * 0.25;
              // if ( length(vCameraPos.xyz) <= 100.0){
              //    gl_FragColor = vec4(1.0, 0., 0., 1.0);
              // }
              vec3 frustumAxis = center - frustum[0];

              vec3 projected = projectOnVector(dir, frustumAxis);
              float scalar = length(frustumAxis) / length(projected);
              vec3 planeProj = ( dir * scalar ) + frustum[0];


              if (calculateCos(dir, frustumAxis) > 0.4) {
                  // UVs
                  vec3 uvBase = planeProj - frustum[1]; // from top-left corner

                  vec3 cBase = planeProj - center;
                  vec3 sub12 = frustum[2] - frustum[1];
                  vec3 sub13 = frustum[3] - frustum[1];
                  vec3 sub12uv = projectOnVector(uvBase, sub12);
                  vec3 sub13uv = projectOnVector(uvBase, sub13);
                  float ou = length(sub12uv) * sign(dot(sub12, sub12uv)) / length(sub12);
                  float ov = 1. - length(sub13uv) * sign(dot(sub13, sub13uv)) / length(sub13);

                  if (useUndistort) {
                      if (isFishEyeModel){
                          float a = (length(sub12uv) * sign(dot(sub12, sub12uv)) - length(sub12) / 2.) / length(frustumAxis);
                          float b = (-(length(sub13uv) * sign(dot(sub13, sub13uv))) + length(sub13) / 2.) / length(frustumAxis);
                          float r = sqrt(a * a + b * b);
                          float theta = atan(r);
                          float thetaD = theta * ( 1. + distCoeff.x * pow(theta, 2.) + distCoeff.y * pow(theta, 4.) + distCoeff.z * pow(theta, 6.) + distCoeff.w * pow(theta, 8.));
                          if (theta > 80. / 180. * 3.1415 ){
                              return;
                          }
                          float x2 = r > 1e-8 ? (thetaD / r)*a : a;
                          float y2 = r > 1e-8 ? (thetaD / r)*b : b;

                          // float u = length(sub12uv) * sign(dot(sub12, sub12uv)) / length(sub12);

                          float u = (x2 * length(frustumAxis) + length(sub12) / 2.) / length(sub12);

                          // float v = length(sub13uv) * sign(dot(sub13, sub13uv)) / length(sub13);

                          float v = (-y2 * length(frustumAxis) + length(sub13) / 2.) / length(sub13);
                          v = 1. - v;
                          if ( calculateCos(dir, frustumAxis) > 0.0) {
                              if ( max( u,v ) <= 1. && min( u, v ) >= 0. ) {
                                  color = texture2D(cameraTexture, vec2(u, v)).rgb * 0.8 + baseTextureColor * (0.2);
                                  gl_FragColor = vec4(baseColor * color, 1.0);
                              }
                          }
                      } else {
                          float a = (length(sub12uv) * sign(dot(sub12, sub12uv)) - length(sub12) / 2.) / length(frustumAxis);
                          float b = (-(length(sub13uv) * sign(dot(sub13, sub13uv))) + length(sub13) / 2.) / length(frustumAxis);
                          float r = sqrt(a * a + b * b);
                          float x2 = a * ( 1. + distCoeff.x * pow(r, 2.) + distCoeff.y * pow(r, 4.) + distCoeff.z * pow(r, 6.) );
                          float y2 = b * ( 1. + distCoeff.x * pow(r, 2.) + distCoeff.y * pow(r, 4.) + distCoeff.z * pow(r, 6.) );
                          float u = (x2 * length(frustumAxis) + length(sub12) / 2.) / length(sub12);
                          float v = (-y2 * length(frustumAxis) + length(sub13) / 2.) / length(sub13);
                          v = 1. - v;
                          // if ( calculateCos(dir, frustumAxis) > 0.0) {
                              if ( max( u,v ) <= 1. && min( u, v ) >= 0. ) {
                                  float opacity = 1.0;
                                  if ( u <= 0.1 || u >= 0.9) {
                                      opacity = 10. * min(u, 1.0-u);
                                  }
                                  if ( v <= 0.1 || v >= 0.9) {
                                      opacity = 10. * min(v, 1.0-v);
                                  }

                                  color = texture2D(cameraTexture, vec2(u, v)).rgb * 1.0 + baseTextureColor * (0.0);
                                  gl_FragColor = vec4(baseColor * color, opacity);
                                  // gl_FragColor = vec4(0.5, 0.0, 0.0, 1.0);
                              }
                          // }
                      }
                  }else{
                      float u = length(sub12uv) * sign(dot(sub12, sub12uv)) / length(sub12);
                      float v = length(sub13uv) * sign(dot(sub13, sub13uv)) / length(sub13);
                      v = 1. - v;
                      if ( calculateCos(dir, frustumAxis) > 0.0) {
                          if ( max( u,v ) <= 1. && min( u, v ) >= 0. ) {
                              color = texture2D(cameraTexture, vec2(u, v)).rgb * 0.8 + baseTextureColor * (0.2);
                              // gl_FragColor = vec4(baseColor * color, 1.0);
                              gl_FragColor = vec4(0.5, 0.0, 0.0, 1.0);
                          }
                      }
                  }
              }
          }
      }
    </script>
  </head>
  <body class="theme-2k"> 
    <div id="app"></div>
    <video id="flv-video" muted loop webkit-playsinline style="display: none" />
    <!-- built files will be auto injected -->
  </body>
</html>
